<template>
  <a-card :bordered="false">
    <!-- 抽屉 -->
    <a-drawer
      :title="$t('light.pattern')"
      :width="screenWidth"
      @close="onClose"
      :visible="visible"
    >
      <!-- 抽屉内容的border -->
      <div
        :style="{
          padding:'10px',
          border: '1px solid #e9e9e9',
          background: '#fff',
        }">
        <div class="table-page-search-wrapper">
        </div>


        <!-- 查询区域-END -->

        <!-- 操作按钮区域 -->
        <div class="table-operator" style="margin-bottom: 5px;">
          <a-button @click="handleAddPattern" type="primary" icon="plus"> {{$t('base.add')}} </a-button>
          <a-button @click="usePattern" type="primary" icon="plus"> {{$t('base.apply')}} </a-button>

        </div>
        <!-- table区域-begin -->
        <div>
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :loading="loading"
            :scroll="{ x: 1000 }"
            :rowSelection="{fixed:true,selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"

            @change="handleTableChange">

            <template slot="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
            <template slot="imgSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px;font-style: italic;">无此图片</span>
              <img v-else :src="getImgView(text)" height="25px" alt="图片不存在" style="max-width:80px;font-size: 12px;font-style: italic;"/>
            </template>
            <template slot="fileSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px;font-style: italic;">无此文件</span>
              <a-button
                v-else
                :ghost="true"
                type="primary"
                icon="download"
                size="small"
                @click="uploadFile(text)">
                下载
              </a-button>
            </template>

            <span slot="action" slot-scope="text, record">
            <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
        </span>
          </a-table>
        </div>
      </div>
    </a-drawer>
    <glr-pattern-gateway-modal ref="modalForm" @ok="modalFormOk"></glr-pattern-gateway-modal>
  </a-card>
</template>

<script>
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { validateDuplicateValue,filterObj } from '@/utils/util'
  import GlrPatternGatewayModal from "./modules/GlrPatternGatewayModal";
  import {httpAction} from '@/api/manage'
  import JInput from '@/components/jeecg/JInput'
  export default {
    name: "GlrPatternGatewayList",
    mixins:[JeecgListMixin],
    components: {
      GlrPatternGatewayModal,
      JInput
    },
    data () {
      return {
        description: this.$t('light.pattern') ,
        visible: false,
        screenWidth: 1300,
        disableMixinCreated:true,
        gateWayCode:'',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:this.$t('light.patternName')  ,
            align:"center",
            dataIndex: 'glrPattern.patternName'
          },
          {
            title:this.$t('light.inApplication') ,
            align:"center",
            dataIndex: 'currentStatus_dictText'
          },
          {
            title:this.$t('light.earlyMorning'),
            align:"center",
            dataIndex: 'glrPattern.commandTimea'
          },
          {
            title:this.$t('light.brightness'),
            align:"center",
            dataIndex: 'glrPattern.brightValuea'
          },
          {
            title:this.$t('light.sunriseLightOffTime'),
            align:"center",
            dataIndex: 'glrPattern.sunupTime'
          },
          {
            title:this.$t('light.brightness')+'b',
            align:"center",
            dataIndex: 'glrPattern.brightValueb'
          },
          {
            title:this.$t('light.sunsetLightOnTime'),
            align:"center",
            dataIndex: 'glrPattern.sunsetTime'
          },
          {
            title:this.$t('light.brightness')+'c',
            align:"center",
            dataIndex: 'glrPattern.brightValuec'
          },
          {
            title:this.$t('light.nightTime')+'1',
            align:"center",
            dataIndex: 'glrPattern.commandTimed'
          },
          {
            title:this.$t('light.brightness')+'d',
            align:"center",
            dataIndex: 'glrPattern.brightValued'
          },
          {
            title:this.$t('light.nightTime')+'2',
            align:"center",
            dataIndex: 'glrPattern.commandTimee'
          },
          {
            title:this.$t('light.brightness')+'e',
            align:"center",
            dataIndex: 'glrPattern.brightValuee'
          },
          {
            title: this.$t('base.operation'),
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/glr/glrPatternGateway/patternGateWayList",
          delete: "/glr/glrPatternGateway/delete",
          deleteBatch: "/glr/glrPatternGateway/deleteBatch",
          usePattern: "/glr/glrPatternGateway/usePattern",
        },
        dictOptions:{
        },
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      initDictConfig(){
      },
      onClose() {
        this.visible = false;
        this.dataSource = [];
      },
      edit(record) {
        this.visible = true;
        this.gateWayCode=record.gateWayCode
        // 当其它模块调用该模块时,调用此方法加载数据
        this.loadData();
      },
      getQueryParams() {
        var param = Object.assign({}, this.queryParam);
        param.gateWayCode = this.gateWayCode;
        return filterObj(param);
      },
      handleAddPattern: function () {
        this.$refs.modalForm.edit(this.gateWayCode);
        this.$refs.modalForm.title = this.$t('light.bindingMode');
        this.$refs.modalForm.disableSubmit = false;
      },
      getAvatarView: function (status) {
        if(status=='Y'){
          return   require('@/assets/img/zaixian.png');
        }else{
          return   require('@/assets/img/lixian.png');
        }

      },
      usePattern: function () {
        if (this.selectionRows.length != 1) {
          this.$message.warning(this.$t('base.pleaseSelectARecord'));
          return;
        } else {
          var gateWayCodes = "";
          var id=""
          var patternId=""
          for (var a = 0; a < this.selectionRows.length; a++) {
            gateWayCodes = this.selectionRows[0].gateWayCode;
            id=this.selectionRows[0].id;
            patternId=this.selectionRows[0].patternId;
          }
          var that = this;
          this.$confirm({
            title: this.$t('base.confirm'),
            content: this.$t('light.confirmApplyPatternToGateway') ,
            onOk: function () {
              that.loading = true;
              httpAction(that.url.usePattern, {patternId:patternId,gateWayCode: gateWayCodes,id:id}, "post").then((res) => {
                if (res.success) {
                  that.$message.success(res.message);
                  that.loadData();
                  that.onClearSelected();
                } else {
                  that.$message.warning(res.message);
                }
              }).finally(() => {
                that.loading = false;
              });
            }
          });
        }
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>